package cn.jsu.oj.dispatchServer.satellite.factory;

import cn.jsu.oj.dispatchServer.satellite.annotation.PackType;
import cn.jsu.oj.dispatchServer.satellite.util.AnnScanUtil;
import cn.jsu.oj.dispatchServer.satellite.util.SpringUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * 包编号工厂
 *
 * @author shan
 * @date 2022/07/04
 */
public class PackNoFactory implements Factory {
    
    private List<Short> packNoList;

    @Override
    public void build() {
        this.packNoList = new ArrayList<>();
        List<Class<?>> classList = AnnScanUtil.scanPackage("cn", PackType.class);
        for (Class<?> clazz : classList) {
            Short typeNo = clazz.getAnnotation(PackType.class).typeNo();
            packNoList.add(typeNo);
        }
        SpringUtil.registerBean("packNoList", this.packNoList.getClass(), true);
    }

    @Override
    public Object getProduct(Short goodsNo) {
        return this.packNoList.contains(goodsNo);
    }
}
